<?php
/**
 * @copyright meila.com
 * @author wangtao5@
 * @name 删除宝贝接口
 * @param 
 *         $nick = 作用
 * 
 * 
 */
include('../../__global.php');
class aj_delGoods extends ml_controller 
{
    private $rid;
    private $arrAlert = array(
        'rid' => 'rid'
    );

    function initParam()
    {
        /**
         * @todo get post
         */
        $this->rid = $this->input('rid', 'P', '');
    }
    /**
     * @develop_template
     * 检查参数合法性
     */
    function checkParam()
    {
        $this->check_referer();
        if(empty($this->rid)){
            $this->api_output(ML_RCODE_PARAM , '', $this->arrAlert['rid']);
        }
        if(!$this->check_permission(ML_PERMISSION_LOGIN_ONLY)) {
            return $this->api_output(ML_RCODE_NOLOGIN);
        }
        else if(!$this->check_permission(ML_PERMISSION_LOGIN_CANWRITE)) {
            return $this->api_output(ML_RCODE_NOACTIVE);
        }
        
        if(ml_tool_resid::resid2uid($this->rid)!=$this->__visitor['uid']){
            $this->api_output(ML_RCODE_PARAM);
        }
        
        
    }
    /**
     * @develop_template
     * 核心业务逻辑
     */
    function main()
    {
        $oContent = new ml_model_dbContent();
        $oUserfeed = new ml_model_dbUserfeed();
        $oPubFeed = new ml_model_dbPublicFeed();
        $oPicFeed = new ml_model_dbPicFeed();
        
        $rDb_content = $oContent->del_contentByRid($this->rid);
        if($rDb_content){
            $rDb_userfeed = $oUserfeed->del_contentByContent_rid($this->rid);
            $oRedis = new ml_model_rdsCount();
            $oRedis->decrUserContentcnt($this->__visitor['uid']);
            $oRedis->decrUserfeedcnt($this->__visitor['uid']);
            
            //$rMq_del = ml_tool_sendMq::goods_del_content($this->rid);
            ml_tool_sendMq::search_content('A', $this->rid);
            ml_tool_sendMq::del_atme_in_content($this->rid);
            ml_tool_sendMq::del_like_feed($this->rid);
            
            ml_tool_actionlog::del_content($this->__visitor['uid'] , $this->rid);
            $this->api_output(ML_RCODE_SUCC);
        }else{
            $this->api_output(ML_RCODE_BUSY);
        }
    }
}

new aj_delGoods();
